package com.situ.controller.cst_linkman;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.customer.CstCustomer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.cst_linkman.CstLinkmanService;
import com.situ.entity.cst_linkman.CstLinkman;
import com.situ.util.*;

import java.util.List;

/**
 * CstLinkman的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class CstLinkmanController {

	/** CstLinkmanService服务 */
	@Autowired
	private CstLinkmanService cstLinkmanService;
	
	/**
	 * 查询所有CstLinkman数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/CstLinkman/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(CstLinkman value) {

		return ResponseData.ok().putDataValue("list",cstLinkmanService.find(value));
	}
	
	/**
	 * 通过id查询CstLinkman数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/CstLinkman/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",cstLinkmanService.findOne(id));
	}
	
	/**
	 * 插入CstLinkman属性不为空的数据方法
	 * @RequestMapping(value = "/CstLinkman/save")
     * 	public ResponseData save(CstLinkman value) {
     * 		return ResponseData.ok().putDataValue("obj", cstLinkmanService.saveNotNull(value));
     * 	}
	 * @return
	 */

	
	/**
	 * 更新CstLinkman属性不为空的数据方法
	 * 
	 * @return
     * 	@RequestMapping(value = "/CstLinkman/update", produces = {"application/json;charset=UTF-8"})
     * 	public ResponseData update(CstLinkman value) {
     * 		return ResponseData.ok().putDataValue("obj",cstLinkmanService.updateNotNullById(value));
     * 	}
	 */


	/**
	 * 通过id删除CstLinkman数据方法
	 * @RequestMapping(value = "/CstLinkman/delById/{id}", produces = {"application/json;charset=UTF-8"})
     * 	public ResponseData delById(@PathVariable(name="id") Long id) {
     * 		return ResponseData.ok().putDataValue("obj",cstLinkmanService.deleteById(id));
     * 	}
	 * @return
	 */



    //带分页的查询全部
//@ApiOperation("带分页的查询全部")
/*
    @RequestMapping(value = "/CstLinkman/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(CstLinkman value,
                             @RequestParam(defaultValue = "1",required = false) int pageNum ,
                             @RequestParam(defaultValue = "5",required = false) int pageSize) {

	    PageHelper.startPage(pageNum, pageSize);
        List<SysMight> list = sysMightService.find2(value);
    PageInfo pageInfo = new PageInfo<SysMight>(list,5);

        return ResponseData.ok()
        // .putDataValue("list", list)
        .putDataValue("pageInfo",pageInfo);
        }
 */

//根据客户编号查询所有联系人
@RequestMapping("/CstLinkman/queryall/{id}")   //springboot 可以直接转json
public List<CstLinkman> queryall(@PathVariable String id) {
    List<CstLinkman> list =cstLinkmanService.querybyid(id);
    return list; //自动转json  springboot

}
//添加联系人
    @RequestMapping(value = "/CstLinkman/save")
    public String save(CstLinkman linkman){
        cstLinkmanService.saveNotNull(linkman);
        return "新建联系人成功";
    }

//修改联系人
   @RequestMapping("/CstLinkman/update")
    public String update(CstLinkman linkman) {
        cstLinkmanService.updateNotNullById(linkman);
        return "修改成功";
}
//删除联系人
    @RequestMapping("/CstLinkman/delById/{id}")
    public String delete(@PathVariable long id) {
        cstLinkmanService.deleteById(id);
        String mess="删除成功";
        return mess;
    }



}
